package com.picturehistory.core.rest.resources;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.picturehistory.core.rest.model.Location;
import com.picturehistory.core.rest.service.LocationService;

@Path("/location")
@Component
public class LocationResource {

	@Autowired
	private LocationService service;
	
	public LocationResource() {}
	
	@GET
	@Produces("plain/text")
	public String resTest() {
		return "ready";
	}
	
	@GET
	@Path("/{lat}/{lng}")
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	public Location getLocationByLatLng(
			@PathParam("lat") Double lat, @PathParam("lng") Double lng) {
		
		return service.getLocationByLatLng(lat, lng);
	}
	
	@POST
	@Path("/{lat}/{lng}")
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	public Location addLocation(
			@PathParam("lat") Double lat, @PathParam("lng") Double lng) {
		Location loc = service.addLocation(lat, lng);
		return loc;
	}
}
